def getText():
    txt=open('test.txt','r').read()
    txt=txt.lower()
    for ch in '!“#$%&（）*+，-。、：；<=>？@[\\]^_`{|}~':
        txt=txt.replace(ch," ")
    return txt
testTxt=getText()
words=testTxt.split()
counts={}
for word in words:
    counts[word]=counts(word,0)+1
items=list(counts.items())
items.sort(key=lambda x:x[1],reverse=True)
with open('output.txt','w',encoding='utf-8')as f:
for i in range(5):
    word,count=items[i]
    print("{0:<10}{1:>5}".format(word,count))
    f.write(f'{word:count}\n')

